package com.guigu.controller;

import com.guigu.dto.TemplateManagementDTO;
import com.guigu.service.TemplateManagementService;
import com.guigu.vo.Result;
import com.guigu.vo.TemplateManagementVO;
import com.guigu.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/TemplateManagement")
public class TemplateManagementController {
    @Autowired
    private TemplateManagementService templateManagementService;

    @GetMapping("/queryFoodByName")
    @ResponseBody
    public Result<List<TemplateManagementVO>> queryFoodByName(TemplateManagementDTO dto) {
        System.out.println(dto.getFoodName());
        List<TemplateManagementVO> list = this.templateManagementService.queryFoodByName(dto);
        return new Result<>("200", "true", "查询成功", list);
    }

    @GetMapping("/queryTemplate_management")
    @ResponseBody
    public Result<List<TemplateManagementVO>> queryTemplate_management(TemplateManagementDTO dto) {
        List<TemplateManagementVO> list = this.templateManagementService.queryTemplate_management(dto);
        return new Result<>("200", "true", "查询成功", list);
    }

    @PostMapping("/addTemplate_management")
    @ResponseBody
    public Result add_diet_template(@RequestBody TemplateManagementDTO templateManagementDTO) {
        System.out.println(templateManagementDTO.getFoodList());
        this.templateManagementService.add_dietary_intervention(templateManagementDTO);
        return new Result<>("200", "true", "添加成功", "无");
    }

    @GetMapping("/querySportsByName")
    @ResponseBody
    public Result<List<TemplateManagementVO>> querySportsByName(TemplateManagementDTO dto) {
        System.out.println(dto.getSportsName());
        List<TemplateManagementVO> list = this.templateManagementService.querySportsByName(dto);
        return new Result<>("200", "true", "查询成功", list);
    }

    @PostMapping("/updateInterveneById")
    @ResponseBody
    public Result updateInterveneById(@RequestBody TemplateManagementDTO templateManagementDTO) {
        this.templateManagementService.updateInterveneById(templateManagementDTO);
        return new Result<>("200", "true", "修改成功", "无");
    }

    @PostMapping("/updateTypeById")
    @ResponseBody
    public Result updateTypeById(@RequestBody TemplateManagementDTO templateManagementDTO) {
        this.templateManagementService.updateTypeById(templateManagementDTO);
        return new Result<>("200", "true", "修改成功", "无");
    }

    @PostMapping("/delTemplate_managementById")
    @ResponseBody
    public Result delTemplate_managementById(@RequestBody TemplateManagementDTO templateManagementDTO) {
        this.templateManagementService.delTemplate_managementById(templateManagementDTO);
        return new Result<>("200", "true", "删除成功", "无");
    }
    @GetMapping("/queryTemplateNameByName")
    @ResponseBody
    public Result<List<TemplateManagementVO>> queryTemplateName(TemplateManagementDTO templateManagementDTO) {
        List<TemplateManagementVO> list = this.templateManagementService.queryTemplateNameByName(templateManagementDTO);
        return new Result<>("200", "true", "查询成功", list);
    }
    @GetMapping("/queryNameByRole")
    @ResponseBody
    public Result<List<UserVO>> queryNameByRole(){
       List<UserVO> userList = this.templateManagementService.queryUserByRole();
        return new Result<>("200", "true", "查询成功", userList);
    }
    @GetMapping("/queryTemplateInfoByName")
    @ResponseBody
    public Result<TemplateManagementVO> queryTemplateInfoByName(TemplateManagementDTO templateManagementDTO){
        return new Result<>("200", "true", "查询成功", this.templateManagementService.queryTemplateInfoByName(templateManagementDTO));
    }

    @GetMapping ("/queryDietById")
    @ResponseBody
    public Result<List<TemplateManagementVO>> queryDietById(TemplateManagementDTO templateManagementDTO){
        return new Result<>("200", "true", "查询成功", this.templateManagementService.queryDietInfo(templateManagementDTO));
    }
    @GetMapping("/querySportsById")
    @ResponseBody
    public Result<List<TemplateManagementVO>> querySportsById(TemplateManagementDTO templateManagementDTO){
        return new Result<>("200", "true", "查询成功", this.templateManagementService.queryExerciseInfo(templateManagementDTO));
    }

}
